
/*
 Abstract：Checking and Requesting Access to Data Classes in Privacy Settings.
 Abstract：检查和请求访问隐私设置数据。
 */


@import Foundation;
@import UIKit;
@import AssetsLibrary;
@import Photos;
@import AddressBook;
@import Contacts;
@import AVFoundation;
@import CoreBluetooth;
@import CoreLocation;
@import EventKit;
@import Speech;
@import HealthKit;
@import HomeKit;
@import StoreKit;
@import CoreMotion;

/*
 Enumerate
 */
// Privacy classify 分类
typedef NS_ENUM(NSUInteger, WXPrivacyType){
    WXPrivacyType_None                  = 0,
    WXPrivacyType_LocationServices      = 1,    // 定位服务
    WXPrivacyType_Contacts              = 2,    // 通讯录
    WXPrivacyType_Calendars             = 3,    // 日历
    WXPrivacyType_Reminders             = 4,    // 提醒事项
    WXPrivacyType_Photos                = 5,    // 照片
    WXPrivacyType_BluetoothSharing      = 6,    // 蓝牙共享
    WXPrivacyType_Microphone            = 7,    // 麦克风
    WXPrivacyType_SpeechRecognition     = 8,    // 语音识别 >= iOS10
    WXPrivacyType_Camera                = 9,    // 相机
    WXPrivacyType_Health                = 10,   // 健康 >= iOS8.0
    WXPrivacyType_HomeKit               = 11,   // 家庭 >= iOS8.0
    WXPrivacyType_MediaAndAppleMusic    = 12,   // 媒体与Apple Music >= iOS9.3
    WXPrivacyType_MotionAndFitness      = 13,   // 运动与健身
};

// WXAuthorizationStatus 权限状态，参考PHAuthorizationStatus等
typedef NS_ENUM(NSUInteger, WXAuthorizationStatus){
    WXAuthorizationStatus_NotDetermined  = 0, // 用户从未进行过授权等处理，首次访问相应内容会提示用户进行授权
    WXAuthorizationStatus_Authorized     = 1, // 已授权
    WXAuthorizationStatus_Denied         = 2, // 拒绝
    WXAuthorizationStatus_Restricted     = 3, // 应用没有相关权限，且当前用户无法改变这个权限，比如:家长控制
    WXAuthorizationStatus_NotSupport     = 4, // 硬件等不支持
};

// WXLocationAuthorizationStatus 定位权限状态，参考CLAuthorizationStatus
typedef NS_ENUM(NSUInteger, WXLocationAuthorizationStatus){
    WXLocationAuthorizationStatus_NotDetermined         = 0, // 用户从未进行过授权等处理，首次访问相应内容会提示用户进行授权
    WXLocationAuthorizationStatus_Authorized            = 1, // 一直允许获取定位 ps：< iOS8用
    WXLocationAuthorizationStatus_Denied                = 2, // 拒绝
    WXLocationAuthorizationStatus_Restricted            = 3, // 应用没有相关权限，且当前用户无法改变这个权限，比如:家长控制
    WXLocationAuthorizationStatus_NotSupport            = 4, // 硬件等不支持
    WXLocationAuthorizationStatus_AuthorizedAlways      = 5, // 一直允许获取定位
    WXLocationAuthorizationStatus_AuthorizedWhenInUse   = 6, // 在使用时允许获取定位
};

// WXCBManagerState 蓝牙状态，参考 CBManagerState
typedef NS_ENUM(NSUInteger, WXCBManagerStatus){
    WXCBManagerStatusUnknown         = 0,        // 未知状态
    WXCBManagerStatusResetting       = 1,        // 正在重置，与系统服务暂时丢失
    WXCBManagerStatusUnsupported     = 2,        // 不支持蓝牙
    WXCBManagerStatusUnauthorized    = 3,        // 未授权
    WXCBManagerStatusPoweredOff      = 4,        // 关闭
    WXCBManagerStatusPoweredOn       = 5,        // 开启并可用
};


/*
 定义权限状态回调block
 */
typedef void(^AccessForTypeResultBlock)(WXAuthorizationStatus status, WXPrivacyType type);
typedef void(^AccessForLocationResultBlock)(WXLocationAuthorizationStatus status);
typedef void(^AccessForBluetoothResultBlock)(WXCBManagerStatus status);
typedef void(^AccessForHomeResultBlock)(BOOL isHaveHomeAccess);
typedef void(^AccessForMotionResultBlock)(BOOL isHaveMotionAccess);


@interface WXAuthorizationTools : NSObject
@property (nonatomic, strong) CLLocationManager         *locationManager;       // 定位
@property (nonatomic, strong) CBCentralManager          *cMgr;                  // 蓝牙
@property (nonatomic, strong) HKHealthStore             *healthStore;           // 健康
@property (nonatomic, strong) HMHomeManager             *homeManager;           // home
@property (nonatomic, strong) CMMotionActivityManager   *cmManager;             // 运动
@property (nonatomic, strong) NSOperationQueue          *motionActivityQueue;   // 运动




#pragma mark -------------------- Public Methods --------------------
/*
 NS_ENUM -> NSString
 */
+ (NSString *)stringForPrivacyType:(WXPrivacyType)privacyType;
+ (NSString *)stringForAuthorizationStatus:(WXAuthorizationStatus)authorizationStatus;
+ (NSString *)stringForLocationAuthorizationStatus:(WXLocationAuthorizationStatus)locationAuthorizationStatus;
+ (NSString *)stringForCBManagerStatus:(WXCBManagerStatus)CBManagerStatus;


#pragma mark -------------------- Main Enter Method --------------------
/**
 Check and request access for * type 
 检查和请求对应类型的权限

 @param type WXPrivacyType
 @param accessStatusCallBack AccessForTypeResultBlock
 */
+ (void)checkAndRequestAccessForType:(WXPrivacyType)type accessStatus:(AccessForTypeResultBlock)accessStatusCallBack;

/**
 Check and request access for LocationServices
 检查和请求定位服务的权限
 
 @param accessStatusCallBack accessStatus
 */
- (void)checkAndRequestAccessForLocationServicesWithAccessStatus:(AccessForLocationResultBlock)accessStatusCallBack;

/**
 Check and request access for BluetoothSharing
 检查和请求蓝牙共享服务的权限

 @param accessStatusCallBack accessStatus
 */
- (void)checkAndRequestAccessForBluetoothSharingWithAccessStatus:(AccessForBluetoothResultBlock)accessStatusCallBack;

/**
 Check and request access for Health
 检查和请求健康的权限
 
 @param accessStatusCallBack accessStatus
 */
- (void)checkAndRequestAccessForHealthWtihAccessStatus:(AccessForTypeResultBlock)accessStatusCallBack;

/**
 Check And Request Access For Home
  Tip：访问家庭权限是需要回调指定的的HMHomeManagerDelegate协议，并且回调之后的后续逻辑处理比较麻烦，建议使用者可以直接调用系统的获取权限方法。在回调协议中做处理。这里做出简单Demo以方便参考。注意：HMError.h类

 @param accessForHomeCallBack AccessForHomeResultBlock
 */
- (void)checkAndRequestAccessForHome:(AccessForHomeResultBlock)accessForHomeCallBack;

/**
 Check And Request Access For Motion And Fitness
 同访问Home一样，运动与健身这里也只给出简单demo方便参考，可以直接copy代码到自己的项目中直接用

 */
- (void)checkAndRequestAccessForMotionAndFitness;

@end














